package logic

import (
	"context"
	"fmt"
	"goods_srv/modile/mysql"

	"goods_srv/goods"
	"goods_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsDetailLogic {
	return &GoodsDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsDetailLogic) GoodsDetail(in *goods.GoodsDetailRequest) (*goods.GoodsDetailResponse, error) {
	// todo: 商品详情

	g := mysql.GoodsLx{}

	err := g.GoodsDetail(int(in.GoodsId))
	if err != nil {
		fmt.Println("查询失败", err)
		return nil, err
	}

	return &goods.GoodsDetailResponse{
		GoodsTitle:  g.GoodsTitle,
		GoodsPrice:  g.GoodsPrice,
		GoodsStock:  g.GoodsStock,
		GoodsStatus: int64(g.GoodsStatus),
		GoodsAvatar: g.GoodsCover,
		GoodsId:     int64(g.ID),
	}, nil
}
